package tx.os3.clientserver.client.model;

import java.util.Date;

/**
 * Class to represent physical files without containing their content.
 * 
 * @author Thomas Middeldorp
 */
public class FileRepresentation {

    enum FileType {
        FILE {
            @Override
            public String toString() {
                return "F";
            }
        },
        DIRECTORY {
            @Override
            public String toString() {
                return "D";
            }
        }
    }

    private String fileName;
    private FileType type;
    private String path;
    private Date lastModified;
    private FileRepresentation parent;

    public static final FileRepresentation createFileRepresentation() {
        return new FileRepresentation();
    }

    private FileRepresentation() {

    }

    public void setFileName(String fileName) {
        if(fileName == null) {
            throw new IllegalArgumentException("File name cannot be null.");
        }
        this.fileName = fileName;
    }

    public String getFileName() {
        return fileName;
    }

    /**
     * Sets the file type.
     * 
     * @param type
     *            The file type to set, cannot be null.
     */
    public void setType(FileType type) {
        if(type == null) {
            throw new IllegalArgumentException("File type cannot be null.");
        }
        this.type = type;
    }

    public FileType getType() {
        return type;
    }

    public void setLastModified(Date date) {
        this.lastModified = date;
    }

    public Date getLastModified() {
        return lastModified;
    }

    /**
     * Determines whether this instance represents a directory or not.
     * 
     * @return True if a directory is represented, false otherwise.
     */
    public boolean isDirectory() {
        return this.type == FileType.DIRECTORY;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getPath() {
        return path;
    }

    /**
     * Gets the full path for this file representation, including the file name.
     * 
     * @return
     */
    public String getFullPath() {
        return this.getPath() + (this.getPath().endsWith("/") ? "" : "/")
                + this.getFileName();
    }

    @Override
    public String toString() {
        return this.getFullPath();
    }

}
